package com.yukh.test.javabase.thread.concurrent.demo1;

public class Producer extends Thread {
	private ProductList products = ProductList.getInstance();

	public void run() {
		int i = 0;

		while (i <= 20) {
			synchronized (products) { // Get lock on product list
				if (products.isFull()) {
					System.out.println("List is full");
					products.notify(); // Release the lock
				} else {
					Product product = new Product(i++); // Produce a product
					products.put(product);
					System.out.println("Produced product " + product.getId());
					products.notify(); // Release lock
				}
			} // Release the lock
		}
	}
}
